﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Security.Cryptography;
using System.IO;
using System.Text;

using CE.User;
using CE.Global;

public partial class UserMessage : MyLanguageBasePage
{
    protected override void InitializeCulture()
    {
        String selectedCulture = CE.Global.General.SetCulture();
        Culture = selectedCulture;
        base.InitializeCulture();

    }
    
    protected string _header;
    protected string _body;
    protected string _footer;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request.Params["errorcode"] != null)
            {
                string _errcode = Request.Params["errorcode"].ToString();

                GetMessage(_errcode);
                lblMessageHeader.Text = _header;
                lblMessageBody.Text = _body;
                lblMessageFooter.Text = _footer;
            }

            if (Session["UMMSG"] != null)
            {               
                string[] val = Session["UMMSG"].ToString().Split(',');
                string _messagetype = val[0].ToString();
                Int32 _errcode = Convert.ToInt32(val[1].ToString());

                if (_messagetype.ToUpper() != "PAYMS")
                {
                    GetMessage(_messagetype, _errcode);
                    lblMessageHeader.Text = _header;
                    lblMessageBody.Text = _body;
                    lblMessageFooter.Text = _footer;
                }
                else if (_messagetype.ToUpper() == "PAYMS")
                {
                    GetPayMessage(_messagetype, _errcode);
                    lblMessageHeader.Text = _header;
                    lblMessageBody.Text = _body;
                    lblMessageFooter.Text = _footer;
                }
            }
            else
            {
                lblMessageHeader.Text = "¡ÅéÇÂæ.com";
                lblMessageBody.Text = "No message found!";
                lblMessageFooter.Text = "Please <a href = '/'><b>click here</b></a> to <b> Home page</b>.!";
            }
        }
    }

    private void GetMessage(string MessageType, Int32 ErrorCode)
    {
        MessageDB _messagedb = new MessageDB();
        DataTable _Message = new DataTable();
        _Message = _messagedb.GetMessage(400, MessageType, ErrorCode);
        if (_Message != null && _Message.Rows.Count > 0)
        {
            if (System.Globalization.CultureInfo.CurrentCulture.Name == "th-TH")
            {
                _header = _Message.Rows[0]["THHeader"].ToString();
                _body = _Message.Rows[0]["THBody"].ToString();
                _footer = _Message.Rows[0]["THFooter"].ToString();
            }
            else
            {
                _header = _Message.Rows[0]["Header"].ToString();
                _body = _Message.Rows[0]["Body"].ToString();
                _footer = _Message.Rows[0]["Footer"].ToString();
            }
        }
        else
        {
            _header = "¡ÅéÇÂæ.com";
            _body = "No message found!";
            _footer = "Please <a href = '/'><b>click here</b></a> to <b> Home page</b>.!";
        }
    }

    private void GetPayMessage(string MessageType, Int32 ErrorCode)
    {
        if (ErrorCode == 101)
        {
            _header = Resources.ErrorMessage.PayErrorHeader;
            _body = Resources.ErrorMessage.PayErrorBody;
            _footer = Resources.ErrorMessage.PayErrorFooter;
        }
        else if (ErrorCode == 102)
        {
            _header = Resources.ErrorMessage.PayErrorHeader;
            _body = Resources.ErrorMessage.PayErrorBody;
            _footer = Resources.ErrorMessage.PayErrorFooter;
        }
        else if (ErrorCode == 103)
        {
            _header = Resources.ErrorMessage.PayErrorHeader;
            _body = Resources.ErrorMessage.PayErrorBody;
            _footer = Resources.ErrorMessage.PayErrorFooter;
        }
        else if (ErrorCode == 104)
        {
            _header = Resources.ErrorMessage.PayErrorHeader;
            _body = Resources.ErrorMessage.PayErrorBody;
            _footer = Resources.ErrorMessage.PayErrorFooter;

        }
        else if (ErrorCode == 105)
        {
            _header = Resources.ErrorMessage.PayErrorHeader;
            _body = Resources.ErrorMessage.PayErrorBody;
            _footer = Resources.ErrorMessage.PayErrorFooter;
        }
        else if (ErrorCode == 106)
        {
            _header = Resources.ErrorMessage.PayErrorHeader;
            _body = Resources.ErrorMessage.PayErrorBody;
            _footer = Resources.ErrorMessage.PayErrorFooter;
        }
        else if (ErrorCode == 107)
        {
            _header = Resources.ErrorMessage.PayErrorHeader;
            _body = Resources.ErrorMessage.PayErrorBody;
            _footer = Resources.ErrorMessage.PayErrorFooter;
        }
        else
        {
            _header = "GluayGluay.com";
            _body = "No message found!";
            _footer = "Please <a href = '/'><b>click here</b></a> to <b> Home page</b>.!";
        }
    }

    private void GetMessage(string ErrorCode)
    {
        if (ErrorCode == "404")
        {
            _header = Resources.UserMessage.MemberShipService; //"Customer Membership Service";
            _body = "Invalid confirmation key.";
            _footer = "Please contact or request confirmation key.";
        }
        else if (ErrorCode == "100")
        {
            _header = Resources.UserMessage.MemberShipService; //"CompareXpress Membership Service";
            _body = "Thank you very much for choosing our service.";
            _footer = "Please check your registered email account to activate and confirm your account registration.";
        }
        else if (ErrorCode == "200")
        {
            _header = Resources.UserMessage.MemberShipService;// "CompareXpress Membership Service";
            _body = "Your account have been activated. You are ready to use your account, now!";
            _footer = Resources.UserMessage.Please + " <a href = '/car-insurance/class-1.aspx'><b>";
            _footer = _footer + Resources.UserMessage.ClickHere + "</b></a> " + Resources.UserMessage.OR + " <b>";
            _footer = _footer + Resources.UserMessage.SignIn + "</b> " + Resources.UserMessage.RequestService;
        }
        else if (ErrorCode == "300")
        {
            _header = Resources.UserMessage.MemberShipService; //"CompareXpress Membership Service";
            _body = "Email confirmation code has been sent to your email address.";
            _footer = Resources.UserMessage.Please + " <a href = '/car-insurance/class-1.aspx'><b>";
            _footer = _footer + Resources.UserMessage.ClickHere + "</b></a> " + Resources.UserMessage.TO + " <b>";
            _footer = _footer + Resources.UserMessage.SignIn + "</b>.!";
        }
        else if (ErrorCode == "500")
        {
            _header = "¡ÅéÇÂæ.com Car Insurance Quote";
            _body = "Your request have been sent to your selected provider. You will be contacted by the provider very soon.!";
            _footer = "Please <a href = 'viewresulthistory.aspx?ResultTitle=101'><b>Click Here</b></a> or <b>Car Insurance</b> to view your result history!<br/><br/>";
        }
        else if (ErrorCode == "CI501")
        {
            _header = "¡ÅéÇÂæ.com Car Insurance Quote";
            _body = "Your car insurance quote and related information have been saved!";
            _footer = "Please <a href = '/car-insurance/class-1'><b>click here</b></a> to login again.";
        }
        else if (ErrorCode == "CI502")
        {
            _header = "¡ÅéÇÂæ.com Car Insurance Quote";
            _body = "Your car insurance quotes cannot be retrieved and could be due to opening multiple tabs or browsers with the same access.";
            _footer = "Kindly <a href = 'logout.aspx'><b>sign out</b></a> and sign in again.";
        }
        else if (ErrorCode == "HF500")
        {
            _header = "¡ÅéÇÂæ.com Home Loan Service";
            _body = "Your request have been sent to your selected financial institution. You will be contacted by the financial institution company very soon.!";
            _footer = "Please <a href = '/'><b>Click Here</b></a> or <b>Home</b> to go ¡ÅéÇÂæ.com's Home page!<br/><br/>Thanks you very much.";
        }
        else if (ErrorCode == "PL500")
        {
            _header = "¡ÅéÇÂæ.com Personal Loans Service";
            _body = "Your request have been sent to your selected financial institution. You will be contacted by the financial institution company very soon.!";
            _footer = "Please <a href = '/'><b>Click Here</b></a> or <b>Home</b> to go ¡ÅéÇÂæ.com's Home page!<br/><br/>Thanks you very much.";
        }
        else if (ErrorCode == "CC500")
        {
            _header = "¡ÅéÇÂæ.com Credit Cards Service";
            _body = "Your request have been sent to your selected financial institution. You will be contacted by the financial institution company very soon.!";
            _footer = "Please <a href = '/'><b>Click Here</b></a> or <b>Home</b> to go ¡ÅéÇÂæ.com's Home page!<br/><br/>Thanks you very much.";
        }
        else if (ErrorCode == "PA500")
        {
            _header = "¡ÅéÇÂæ.com Personal Accidents Service";
            _body = "Your request have been sent to your selected financial institution. You will be contacted by the financial institution company very soon.!";
            _footer = "Please <a href = '/'><b>Click Here</b></a> or <b>Home</b> to go ¡ÅéÇÂæ.com's Home page!<br/><br/>Thanks you very much.";
        }
        else if (ErrorCode == "TA500")
        {
            _header = "¡ÅéÇÂæ.com Travel Insurance Service";
            _body = "Your request have been sent to your selected financial institution. You will be contacted by the financial institution company very soon.!";
            _footer = "Please <a href = '/'><b>Click Here</b></a> or <b>Home</b> to go ¡ÅéÇÂæ.com's Home page!<br/><br/>Thanks you very much.";
        }
        else if (ErrorCode == "601")
        {
            _header = "¡ÅéÇÂæ.com Car Insurance Service";
            _body = "Select result history record deleting failed. Please try again later!";
            _footer = "Please <a href = '../car_insurance/profile.aspx'><b>Click Here</b></a> or <b>Car Insurance</b> to start new car insurance quote!<br/><br/>";
        }
        else if (ErrorCode == "101")
        {
            _header = "¡ÅéÇÂæ.com Car Insurance Quote";
            _body = "Your account session is time out!";
            _footer = "Please <a href = '/car-insurance/class-1.aspx'><b>Click Here</b></a> or Click <b>Sign In</b> again!<br/><br/>";
            _footer += "<b>Click to send Feed Back :</b> <a href='userfeedback.aspx'>Site Admin</a>";
        }
        else if (ErrorCode == "911")
        {
            _header = Resources.UserMessage.Feedback; //"CompareXpress Feedback";
            _body = Resources.UserMessage.Feedbacksent; //"Your feedback has been sent!";
            _footer = Resources.UserMessage.FeedbackThankyou; //"Thank you very much for you feedback.
            _footer = _footer + "<br /> <br /> <b>¡ÅéÇÂæ.com Team<b>";
        }
        else if (ErrorCode == "199")
        {
            _header = Resources.UserMessage.PasswordRecovery;// "CompareXpress Password Recovery";
            _body = Resources.UserMessage.PasswordRecoveryMessage1; //"Password recovery information has been sent to your email. Please check email inbox now.";
            _footer = Resources.UserMessage.Please + " <a href = '/car-insurance/sign-in.aspx'><b>";
            _footer = _footer + Resources.UserMessage.ClickHere + "</b></a> " + Resources.UserMessage.OR + " <b>";
            _footer = _footer + Resources.UserMessage.SignIn + "</b> " + Resources.UserMessage.RequestService;
        }
        else if (ErrorCode == "1991")
        {
            _header = Resources.Menu.MemberShipService; //"CompareXpress Membership Service";
            _body = "New Password has been changed.";
            _footer = Resources.UserMessage.Please + " <a href = '/car-insurance/class-1.aspx'><b>";
            _footer = _footer + Resources.UserMessage.ClickHere + "</b></a> " + Resources.UserMessage.OR + " <b>";
            _footer = _footer + Resources.UserMessage.SignIn + "</b> " + Resources.UserMessage.RequestService;
        }
        else if (ErrorCode == "1992")
        {
            _header = Resources.Menu.MemberShipService;// "CompareXpress Membership Service";
            _body = "New Password has been reset.";
            _footer = Resources.UserMessage.Please + " <a href = '/car-insurance/class-1.aspx'><b>";
            _footer = _footer + Resources.UserMessage.ClickHere + "</b></a> " + Resources.UserMessage.OR + " <b>";
            _footer = _footer + Resources.UserMessage.SignIn + "</b> " + Resources.UserMessage.RequestService;
        }
        else if (ErrorCode == "1993")
        {
            _header = Resources.Menu.MemberShipService; //"CompareXpress Membership Service";
            _body = Resources.Menu.SessionLocked;//"Please try again later. Your session has been locked!";
            _footer = Resources.UserMessage.Please + " <a href = '/car-insurance/class-1.aspx'><b>";
            _footer = _footer + Resources.UserMessage.ClickHere + "</b></a> " + Resources.UserMessage.OR + " <b>";
            _footer = _footer + Resources.UserMessage.SignIn + "</b> " + Resources.UserMessage.RequestService;
        }

        CE.Global.General.ClearAllSession(this.Page, "ALL");
    }

}
